﻿

using System;
using System.Net;
using System.Text;

namespace n_MQTT
{
	public static class MQTT
	{
		public delegate void D_MessageReceived( string mes );
		public static D_MessageReceived MessageReceived;
		
		public static void Init()
		{
			
		}
		
		public static void Close()
		{
			
		}
		
		//发送消息
		public static void Send( string topic, string mes )
		{
			
		}
		
	}
}





/*

using System;
using System.Net;
using M2Mqtt;
using M2Mqtt.Net.Messages;
using M2Mqtt.Net;
using System.Text;

namespace n_MQTT
{
	public static class MQTT
	{
		public delegate void D_MessageReceived( string mes );
		public static D_MessageReceived MessageReceived;
		
		static MqttClient client;
		
		public static void Init()
		{
			client = new MqttClient("39.96.23.157"); //主机为IP时
			//MqttClient client = new MqttClient(MQTT_BROKER_ADDRESS); //当主机地址为域名时
			
			// 注册消息接收处理事件，还可以注册消息订阅成功、取消订阅成功、与服务器断开等事件处理函数
			client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
			
			client.MqttMsgSubscribed += client_MqttMsgSubscribed;
			client.MqttMsgPublished += client_MqttMsgPublished;
			
			//生成客户端ID并连接服务器
			string clientId = Guid.NewGuid().ToString();
			client.Connect(clientId, "admin45678", "password" );
			
			// 订阅主题"/home/temperature" 消息质量为 2
			client.Subscribe(new string[] { "linkboy" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
		}
		
		public static void Close()
		{
			if( client != null && client.IsConnected ) {
				client.Disconnect();
			}
		}
		
		//发送消息
		public static void Send( string topic, string mes )
		{
			 client.Publish( topic, Encoding.UTF8.GetBytes(mes) );
		}
		
		static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
		{
			//处理接收到的消息
			string msg = System.Text.Encoding.Default.GetString(e.Message);
			
			if( MessageReceived != null ) {
				MessageReceived( msg );
			}
		}
		
		static void client_MqttMsgUnsubscribed(object sender, MqttMsgUnsubscribedEventArgs e)
		{
			// write your code
		}
		
		static void client_MqttMsgSubscribed(object sender, MqttMsgSubscribedEventArgs e)
		{
			// write your code
		}
		
		static void client_MqttMsgPublished(object sender, MqttMsgPublishedEventArgs e)
		{
			// write your code
		}
	}
}

*/
